package com.dk.common.dbaccess.listener;

import lombok.Setter;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

import jakarta.persistence.PrePersist;
import jakarta.persistence.PreUpdate;

public class AuditingEntityListener {
    @Setter
    @Nullable
    private static AuditingHandler handler;

    @PrePersist
    public void touchForCreate(Object target) {
        Assert.notNull(target, "Entity must not be null!");
        if (handler != null) {
            handler.markCreated(target);
        }
    }

    @PreUpdate
    public void touchForUpdate(Object target) {
        Assert.notNull(target, "Entity must not be null!");
        if (handler != null) {
            handler.markModified(target);
        }
    }
}
